set more off
use "~/Dropbox/Delegation-ML-Project/FINAL-OUTPUT-DATA/APSR_RnR/Application Data/franchino_replication_data.dta", clear
joinby Number using "~/Dropbox/Delegation-ML-Project/FINAL-OUTPUT-DATA/APSR_RnR/Application Data/discretion-subsamples-data.dta", unmatched(both) _merge(_merge)
tab _m

capture log close
log using "~/Dropbox/Delegation-ML-Project/FINAL-OUTPUT-DATA/APSR_RnR/Application Data/replication_subsamples.smcl", replace
** Replication of Table 5.6

*drop cook* 

/// Express our discretion indices as percentages like Franchino

g dg10 = discretionms10*100
g dg20 = discretionms20*100
g dg40 = discretionms40*100

g oursampleg = 0
replace oursampleg = 1 if dg10!=. & dg !=.


/// Replicate Franchino Table

// foreach var in dg dg_full dg_nt dg_na{

// 	qui reg `var' Prog_and_Comm DR_bin IntegrationRange AV LeftRightRange
// 	predict cookm1`var', cooksd
// 	g outm1`var' = 0
// 	recode outm1`var' 0=1 if cookm1`var'>(4/158)
// 	qui reg `var' Prog_and_Comm DR_bin IntegrationRange AV LeftRightRange if !outm1`var', r
// 	est sto m_`var'
	
// }

// esttab m_dg m_dg_full m_dg_nt m_dg_na,  b(%9.3f) t(%9.2f) ar2(%9.2f) star(* 0.10 ** 0.05 *** 0.01) label

foreach var in dg dg10 dg20 dg40{

	qui tobit `var' Prog_and_Comm DR_bin IntegrationRange AV LeftRightRange, ll(0)
	est sto mt_`var'
	
}

qui tobit dg Prog_and_Comm DR_bin IntegrationRange AV LeftRightRange if oursampleg, ll(0)
	est sto mt_os
	
esttab mt_dg mt_os mt_dg10 mt_dg20 mt_dg40, b(%9.3f) t(%9.2f) drop(var*) pr2(%9.2f) star(* 0.10 ** 0.05 *** 0.01) label


** Replication of Table 5.9 -- Right panel with commissioner preferences, Full Model 4b

/// Express our discretion indices as percentages like Franchino

g dc10 = discretioncom10*100
g dc20 = discretioncom20*100
g dc40 = discretioncom40*100

g oursamplec = 0
replace oursamplec = 1 if dc10!=. & dc !=.


// 	qui reg dc DetRules DR_bin CT
// 	predict cookm5, cooksd
// 	g outm5 = 0
// 	recode outm5 0=1 if cookm5>(4/158)
// 	reg dc DetRules DR_bin CT if !outm5, r
// 	est sto m1b
	
// 	qui reg dc DetRules DR_bin DA
// 	predict cookm6, cooksd
// 	g outm6 = 0
// 	recode outm6 0=1 if cookm6>(4/158)
// 	reg dc DetRules DR_bin DA if !outm6, r
// 	est sto m2b
	
// 	qui reg dc DetRules DR_bin CW
// 	predict cookm7, cooksd
// 	g outm7 = 0
// 	recode outm7 0=1 if cookm7>(4/158)
// 	reg dc DetRules DR_bin CW if !outm7, r
// 	est sto m3b

foreach var in dc dc10 dc20 dc40{

// 	qui reg `var' DetRules DR_bin CT DA CW
// 	predict cookm8`var', cooksd
// 	g outm8`var' = 0
// 	recode outm8`var' 0=1 if cookm8`var'>(4/158)
// 	qui reg `var' DetRules DR_bin CT DA CW if !outm8`var', r
// 	est sto m4b_`var'
	
	qui tobit `var' DetRules DR_bin CT DA CW, ll(0)
	est sto m5b_`var'
}

qui tobit dc DetRules DR_bin CT DA CW if oursamplec, ll(0)
est sto m5b_os

//	esttab m4b_dc m4b_dc_full m4b_dc_nt m4b_dc_na,  b(%9.3f) t(%9.2f) ar2(%9.2f) star(* 0.10 ** 0.05 *** 0.01) label

esttab m5b_dc m5b_os m5b_dc10 m5b_dc20 m5b_dc40, b(%9.3f) t(%9.2f) pr2(%9.2f) drop(var*)  star(* 0.10 ** 0.05 *** 0.01) label
